/**
 * [495] 提莫攻击
 *
 * @format
 * @lc app=leetcode.cn id=495 lang=javascript
 */

// @lc code=start
/**
 * @param {number[]} timeSeries
 * @param {number} duration
 * @return {number}
 */
var findPoisonedDuration = function (timeSeries, duration) {
    let result = (start = end = 0)
    timeSeries.forEach((e) => {
        if (e > end) {
            result += end - start
            start = e
            end = e + duration
        } else {
            end = e + duration
        }
    })
    result += end - start
    return result
}
// @lc code=end
